package com.ruoyi.project.tickets.controller;

import java.util.List;

import com.ruoyi.project.tickets.domain.dto.PushDto;
import com.ruoyi.project.tickets.domain.vo.PushVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.Push;
import com.ruoyi.project.tickets.service.IPushService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 发布票券Controller
 * 
 * @author ruoyi
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/tickets/push")
public class PushController extends BaseController
{
    @Autowired
    private IPushService pushService;

    /**
     * 查询发布票券列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(Push push)
    {
        startPage();
        List<PushVo> list = pushService.selectPushList(push);
        return getDataTable(list);
    }

    /**
     * 导出发布票券列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:export')")
    @Log(title = "发布票券", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Push push)
    {
        List<PushVo> list = pushService.selectPushList(push);
        ExcelUtil<PushVo> util = new ExcelUtil<PushVo>(PushVo.class);
        return util.exportExcel(list, "push");
    }

    /**
     * 获取发布票券详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pushService.selectPushById(id));
    }

    /**
     * 新增发布票券
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:add')")
    @Log(title = "发布票券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add( @RequestBody List<PushDto> dto)
    {
        return toAjax(pushService.insertPush(dto));
    }

    /**
     * 修改发布票券
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:edit')")
    @Log(title = "发布票券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Push push)
    {
        return toAjax(pushService.updatePush(push));
    }

    /**
     * 删除发布票券
     */
    @PreAuthorize("@ss.hasPermi('tickets:push:remove')")
    @Log(title = "发布票券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pushService.deletePushByIds(ids));
    }
}
